#include "StatisticalOutlierRemovalModel.h"

#include "core/AppDirectory.h"

namespace {
const QString UserFilename = "pcl.statistical_outlierre_moval_model.json";
}

StatisticalOutlierRemovalModel::StatisticalOutlierRemovalModel()
    : BasePclModel()
{
    setPclHelpPage("https://pcl.readthedocs.io/projects/tutorials/en/master/statistical_outlier.html");
}

StatisticalOutlierRemovalModel& StatisticalOutlierRemovalModel::get()
{
    static StatisticalOutlierRemovalModel instance;
    if (instance.filename().isEmpty()) {
        instance.setFilename(AppDirectory::get().getAppDocFile(UserFilename));
        instance.load();
    }
    return instance;
}

void StatisticalOutlierRemovalModel::fromJson(const QJsonObject& json, QStringList& errorList)
{

    BasePclModel::fromJson(json, errorList);

    pcdFile_ = json["pcdFile"].toString(pcdFile_);
    meanK_ = json["meanK"].toInt(meanK_);
    stddevMulThresh_ = json["StddevMulThresh"].toDouble(stddevMulThresh_);
    negative_ = json["negative"].toBool(negative_);
}

QJsonObject StatisticalOutlierRemovalModel::toJson() const
{
    QJsonObject json = BasePclModel::toJson();

    json.insert("pcdFile", QJsonValue(pcdFile_));
    json.insert("meanK", QJsonValue(meanK_));
    json.insert("StddevMulThresh", QJsonValue(stddevMulThresh_));
    json.insert("negative", QJsonValue(negative_));

    return json;
}
